<%@ page language="java" import="java.util.*,org.dom4j.*" pageEncoding="GB2312"%>
<%@ page import="org.lab.xmlparser.Parserxml"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'parser.jsp' starting page</title>
    <script type="text/javascript" src="<%=path %>/js/jquery.js"></script>
	<script type="text/javascript" src="<%=path %>/js/dtree.js"></script>
	<link rel="stylesheet" type="text/css" href="<%=path %>/css/dtree.css">
	<link rel="stylesheet" type="text/css" href="<%=path %>/css/styles.css">
<%
String name2 = "";
String name1 = "";
if(request.getParameter("name1")!=null){
	name2 = request.getParameter("name1"); 
	name1 = new String(name2.getBytes("ISO-8859-1"),"GB2312");
}%>
	
  </head>
  
  <body>
  <% if(!"".equals(name1)){%>
   <script type="text/javascript">
		var d = new dTree('d');
		d.add(0,-1,'Metric Model');
		<% Parserxml pxml = new Parserxml();
	
		Document doc = pxml.getDocument(getServletContext().getRealPath("/metricmodel/"+name1+".xml"));
		System.out.println("this address is:" + getServletContext().getRealPath("/metricmodel/"+name1+".xml"));
		   Element eleName = pxml.getNode(doc,"//xpdl/Package/MetricModel/Name");
		   String name = eleName.getText();
		   
		   %>d.add(1,0,'<%=name%>','','','','','','');<%
		   
		   Element ele = pxml.getNode(doc,"//xpdl/Package/MetricModel");
				List<Element> list = ele.elements();
				List<String> allName = new LinkedList<String>();
				int num = 0;
				
				for(int i = 0 ; i < list.size();i++){
					Element elem = list.get(i);
					if("MetricElement".equals(elem.getName())){
						List<Element> l = elem.elements();
						for(int j = 0 ; j < l.size() ; j++){
							if(!(l.get(j).getText().indexOf(" ")>0) && !l.get(j).getText().equals(" ") && ! l.get(j).getText().equals("") && l.get(j).getText()!=null){
								allName.add(l.get(j).getText());
							}
						}
						num++;
					}
				}
			for(int k = 0; k < num ; k++){
				%>d.add(<%=k+2%>,1,'MetricElement','','','','','','');<%
			}
			int num1=num;
			for(int j = 0 ; j < allName.size(); j++){
				%>d.add(<%=j+2+num%>,2,'<%=allName.get(j)%>','','','','','','');<%
				num1++;
				}
			%>
			<% Element metricnameele = pxml.getNode(doc,"//xpdl/Package/MetricModel/MetricElement/MetricName");
				List<Element> l1 = metricnameele.elements();
				List<String> nm1 = new LinkedList<String>();
				for(int i = 0; i < l1.size(); i++){
					if(l1.get(i).getText().indexOf(" ")>0 && !l1.get(i).getText().equals(" ") && !l1.get(i).getText().equals("")){
						nm1.add(l1.get(i).getText());
					}
				}
			for(int j=0; j<nm1.size();j++){
			System.out.println("wwwwwwwwwwwwww" + nm1.get(j));%>
			d.add(<%=j+2+num1%>,2,'<%=nm1.get(j)%>','','','','','','');<%}
			   Element functionele = pxml.getNode(doc,"//xpdl/Package/MetricModel/MetricElement/Function");
			   List<Element> l2 = metricnameele.elements();
				List<String> nm2 = new LinkedList<String>();
				for(int i = 0; i < l2.size(); i++){
					if(l2.get(i).getText().indexOf(" ")>0 && !l2.get(i).getText().equals(" ") && !l2.get(i).getText().equals("")){
						nm2.add(l2.get(i).getText());
					}
				}
			int num2=num1;
			for(int j=0; j<nm2.size();j++){%>
			d.add(<%=j+2+num1%>,2,'<%=nm1.get(j)%>','','','','','','');<% num2++;}
			   Element frequencyele = pxml.getNode(doc,"//xpdl/Package/MetricModel/MetricElement/Frequency");
			   List<Element> l3 = metricnameele.elements();
				List<String> nm3 = new LinkedList<String>();
				for(int i = 0; i < l3.size(); i++){
					if(l3.get(i).getText().indexOf(" ")>0 && !l3.get(i).getText().equals(" ") && !l3.get(i).getText().equals("")){
						nm3.add(l3.get(i).getText());
					}
				}
			int num3=num2; 
			for(int j=0; j<nm3.size();j++){%>
			d.add(<%=j+2+num2%>,2,'<%=nm3.get(j)%>','','','','','','');<% num3++;}
			   Element mmetricnameele = pxml.getNode(doc,"//xpdl/Package/MetricModel/MetricElement/MmetricName");
			   List<Element> l4 = metricnameele.elements();
				List<String> nm4 = new LinkedList<String>();
				for(int i = 0; i < l4.size(); i++){
					if(l4.get(i).getText().indexOf(" ")>0 && !l4.get(i).getText().equals(" ") && !l4.get(i).getText().equals("")){
						nm4.add(l4.get(i).getText());
					}
				}%>
			<% int num4 = num3;
			for(int j=0; j<nm4.size();j++){%>
			d.add(<%=j+2+num3%>,2,'<%=nm4.get(j)%>','','','','','','');<% num4++;}
			   Element mfunctionele = pxml.getNode(doc,"//xpdl/Package/MetricModel/MetricElement/Mfunction");
			   List<Element> l5 = metricnameele.elements();
				List<String> nm5 = new LinkedList<String>();
				for(int i = 0; i < l5.size(); i++){
					if(l5.get(i).getText().indexOf(" ")>0 && !l5.get(i).getText().equals(" ") && !l5.get(i).getText().equals("")){
						nm5.add(l5.get(i).getText());
					}
				} 
			int num5 = num4;
			for(int j=0; j<nm5.size();j++){%>
			d.add(<%=j+2+num4%>,2,'<%=nm5.get(j)%>','','','','','','');<%num5++;}
			   Element conditionele = pxml.getNode(doc,"//xpdl/Package/MetricModel/MetricElement/Condition");
			   List<Element> l6 = metricnameele.elements();
				List<String> nm6 = new LinkedList<String>();
				for(int i = 0; i < l6.size(); i++){
					if(l6.get(i).getText().indexOf(" ")>0 && !l6.get(i).getText().equals(" ") && !l6.get(i).getText().equals("")){
						nm6.add(l6.get(i).getText());
					}
				}
			int num6=num5;
			for(int j=0; j<nm6.size();j++){%>
			d.add(<%=j+2+num5%>,2,'<%=nm6.get(j)%>','','','','','','');<%num6++;}
			   Element treatmentele = pxml.getNode(doc,"//xpdl/Package/MetricModel/MetricElement/Treatment");
			   List<Element> l7 = metricnameele.elements();
				List<String> nm7 = new LinkedList<String>();
				for(int i = 0; i < l7.size(); i++){
					if(l7.get(i).getText().indexOf(" ")>0 && !l7.get(i).getText().equals(" ") && !l7.get(i).getText().equals("")){
						nm7.add(l7.get(i).getText());
					}
				}
			for(int j=0; j<nm7.size();j++){%>
			d.add(<%=j+2+num6%>,2,'<%=nm7.get(j)%>','','','','','','');<%}%>
			document.write(d);
	</script>
	<%} %>
	
  </body>
</html>
